Skip to content

Conversation

oliveror
Copy link
Member

Overlaps the PR for #121: both change RecipeCreatePage.tsx and its tests, in different parts. Whichever merges second needs an update from dev.

Changes

  • One source for the limits: MAX_INGREDIENTS (100), MAX_INSTRUCTIONS (100), MAX_TAGS (30) and MAX_TAG_LENGTH (50) now live in @t31/validation/recipe, next to the servings limits. The API's Zod schema and the recipe form both use them, so the two can't disagree.
  • Tags
    • The form now parses tags with a shared parseTags(): trimmed, lower-case, empty entries and repeats removed. It counts and sends exactly what the API stores. Before, "Quick, quick" was sent as two tags, and the API checks max(30) before it removes repeats.
    • More than 30 tags, or a tag over 50 characters, is now a field error on Tags, with the number or the offending tag in the message. Previously this was a generic API error after submitting.
    • The Tags help text states both limits, and the field got an id.
  • Rows
    • Add ingredient and Add step are disabled at 100, with a visible explanation linked through aria-describedby.
    • A recipe or restored draft with more rows than allowed gets a message above the list ("… Remove 1 to save.") that receives focus.
  • Focus after a failed submit: focus moves to the first invalid control in page order ([aria-invalid="true"], or a row-count message). Before, a fixed list only knew the first ingredient and step, so an error in row 2 or later sent focus back to the title.

Validation

  • npm run check passes (277 unit tests). New tests:
    • 31 tags, and a 51-character tag: field error, focus on Tags, nothing sent
    • 30 distinct tags written 60 times in mixed case are accepted and sent as 30 lower-case tags
    • focus lands on Ingredient 2 amount, then on Step 3, when those are the first invalid fields
    • at the row limit, both Add buttons are disabled with their explanation, and removing a row enables Add again
    • a recipe over the limit gets the focused count message and no save request
    • parseTags()
  • The tag and focus tests fail on the previous commit.
  • The two row-limit tests lower the limits to 3 with vi.mock (in RecipeCreatePage.limits.test.tsx). Rendering 2×100 rows took about 4 s in jsdom, close to the 5 s test limit on CI.
  • test:api passes (the API schema now reads the shared constants).

AI usage

Written with Claude Code (Anthropic) to address a teammate's issue. Please review the diff as you would any other contribution.

Closes #120

…id row

- MAX_INGREDIENTS, MAX_INSTRUCTIONS, MAX_TAGS and MAX_TAG_LENGTH live in
  @t31/validation/recipe and are used by the API schema and the form.
- Tags are parsed with the shared parseTags() (trimmed, lower-case, no
  repeats), so the form counts and sends what the API stores. More than
  30 tags or a tag over 50 characters is a field error on Tags.
- Add ingredient / Add step are disabled at the limit with a visible
  explanation; a recipe or restored draft with too many rows gets a
  message above the list.
- After a failed submit, focus moves to the first invalid control in
  page order (any row), instead of a fixed list that only knew row 1.

Closes #120
Copy link
Member

@olestan olestan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Two minot issues with the row-limit error handling should probably be addressed before merging:

  • Errors disappear too early (RecipeCreatePage.tsx:330,385): Removing one ingredient or step clears the count error, even if the list still exceeds 100 rows. Keep the error visible and update the remaining count until the limit is satisfied.
  • Restored drafts don't show limit errors (RecipeCreatePage.tsx:264): Restoring a draft with more than 100 rows clears all errors, so users only discover the issue when submitting. Show the count warning immediately when an over-limit draft is restored.

Removing one ingredient or step cleared the "at most 100" message even when
the list still had too many rows, so the form looked valid until the next
submit. The message now stays and shows the remaining number to remove,
and goes away only when the list fits.

Restoring a draft with more rows than the API accepts also cleared every
error, so the problem only appeared on submit. Restoring now shows the
row-count messages straight away. Both paths share one helper, built on
MAX_INGREDIENTS and MAX_INSTRUCTIONS from @t31/validation/recipe, which
validation on submit uses as well.

Tests: the message recounts after each removal and clears at the limit
(ingredients and steps); an over-limit draft shows both messages when
restored.
@oliveror
Copy link
Member Author

Follow-up commit addressing review:

  • 581a833: The "at most 100 ingredients/steps" message now stays when you remove a row but the list is still over the limit, and shows the remaining count; it goes away only once the list fits. Restoring a draft with too many rows now shows the count messages immediately instead of clearing all errors. Both use one rowCountErrors helper built on MAX_INGREDIENTS and MAX_INSTRUCTIONS (shared with submit validation). Test added for each case in RecipeCreatePage.limits.test.tsx.

@oliveror oliveror merged commit 36fa3eb into dev Nov 17, 2026
2 checks passed
@oliveror oliveror deleted the fix/recipe-form-limits branch November 20, 2026 15:31
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants